/*
 * ground.c
 *
 * 地面関係
 */
#include "spec.h"
#include "vardecl.h"
#include "funcdecl.h"

/*
========================================
  地面関係初期化
========================================
*/
static time_t lim;

void
InitGround(int round)
{
  int i, j;

  lim = 0;
  GroundScale = DEFGRSCALE * OBJ_SCALE; /* 地面の大きさの初期化 */
  GroundEdgeLoc = DEFGREDGE; /* 地面端の座標初期化 */
  /*  */
  groundMaterial.ambient  = 0x3fff;
  groundMaterial.diffuse  = 0x3fff;
  groundMaterial.specular = 0x00ff;
  AGLSetMaterial(&groundMaterial, 1);
  for (i = GROUND0; i < GROUND_MAX; i++) {
    Ground[i].geometryTop = (int *)grdatTable[round - 1];
    Ground[i].geometryLength = grdatLength[round - 1];
    Ground[i].material = &groundMaterial;
  }
  /* 地面位置の初期化 */
  for (i = GROUND0; i < GROUND_MAX; i++) {
    int j;

    for (j = 0; j < 3; j++)
      GroundLoc[i][j] = OrigGroundLoc[i][j] * DEFGREDGE / OBJ_SCALE;
  }
}

/*
========================================
  地面位置・残り時間による大きさ計算
========================================
*/
#define TIMELIMIT (15)        /* 地面が小さくなり始める時間 */
#define LIM (TIMELIMIT * 10)	/* 要調整 */

void
SetGround()
{
  int i;
  time_t tim;

  /* 残りタイムがリミットに達しているか？ */
  tim = GetRestTime();
  if (tim >= TIMELIMIT)
    return;

  if (lim == 0)
    lim = LIM;

  GroundScale = (DEFGRSCALE * OBJ_SCALE * lim) / LIM;
  GroundEdgeLoc = (DEFGREDGE * lim) / LIM;

  for (i = GROUND0; i < GROUND_MAX; i++) {
    GroundLoc[i][LX] = 
      ((int)OrigGroundLoc[i][LX] * DEFGREDGE / OBJ_SCALE * lim) / LIM;
    GroundLoc[i][LY] = 
      ((int)OrigGroundLoc[i][LY] * DEFGREDGE / OBJ_SCALE * lim) / LIM;
  }
  lim--;
}
